
// 152. 乘积最大子数组
class Solution {
public:
    int maxProduct(vector<int>& nums) {
        // 使用动态规划来解决
        int n = nums.size();
        vector<int> f(n) , g(n);
        f[0] = g[0] = nums[0];
        int ret = f[0];
        for(int i = 1 ; i < n ; i++)
        {
            f[i] = max(nums[i] , max(g[i - 1]*nums[i] , f[i - 1]*nums[i]));
            g[i] = min(nums[i] , min(g[i - 1]*nums[i] , f[i - 1]*nums[i]));
            ret = max(ret , f[i]);
        }
        return ret;
    }
};